#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
清算 - 结算资金查询功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.model.clearing import AccBalanceRequest
from jlpay.services.clearing_service import ClearingService


class AccBalanceQueryExample(BaseExample):
    """结算资金查询示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.clearing.settlement.balance")
        # 创建ClearingService实例
        self.clearing_service = ClearingService(self.config)
    
    def build_acc_balance_request(self):
        """构建结算资金查询请求"""
        request = AccBalanceRequest()
        
        # 设置请求参数
        request.set_org_no("123456")
        request.set_merch_no("849584358120018")
        request.set_acct_type("01")  # 账户类型
        
        return request
    
    def demo(self):
        """执行结算资金查询示例"""
        self.logger.info("开始执行结算资金查询示例")
        
        # 创建结算资金查询请求
        request = self.build_acc_balance_request()
        
        # 发送请求并处理响应
        response = self.send_request_and_handle_response(
            self.clearing_service.query_acc_balance,
            "结算资金查询",
            request
        )
        
        # 处理响应结果
        if response and response.is_success():
            self.logger.info(f"响应报文：{response.to_dict()}")
        
        self.logger.info("结算资金查询示例执行完毕")


if __name__ == "__main__":
    logger = AccBalanceQueryExample().logger
    logger.info("==================================================")
    logger.info("===== 结算资金查询示例 开始 =====")
    logger.info("==================================================")
    
    example = AccBalanceQueryExample()
    example.demo()
    
    logger.info("==================================================")
    logger.info("===== 结算资金查询示例执行完毕 =====")
    logger.info("==================================================") 